package cn.ronghuanet.auth.controller;

import cn.ronghuanet.auth.annotation.RonghuaPermission;
import cn.ronghuanet.auth.domain.Permission;
import cn.ronghuanet.auth.query.PermissionQuery;
import cn.ronghuanet.auth.service.IPermissionServiceI;
import cn.ronghuanet.base.util.AjaxResult;
import cn.ronghuanet.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
@RonghuaPermission(name="权限管理",descs = "权限的api接口")
public class PermissionController {
    @Autowired
    private IPermissionServiceI service;

    @RonghuaPermission(name="权限列表",descs = "权限列表高级查询接口")
    @PutMapping
    public AjaxResult queryPage(@RequestBody PermissionQuery permissionQuery){
        try {
            PageInfo<Permission> list = service.queryPage(permissionQuery);
            return AjaxResult.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    @RonghuaPermission(name="获取权限",descs = "获取权限和其子权限")
    @GetMapping
    public AjaxResult queryPermission(){
        try {
            List<Permission> list = service.queryPermission();
            return AjaxResult.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }
}
